<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>deep 选项的使用</title>
</head>
<body>
<div id="app">
    <h1>{{ count }}</h1>
    <button @click="buttonClicked">点击+1</button>

    <hr>
    <h2>姓名：{{ person.name}}</h2>
    <h2>年龄：{{ person.age}}</h2>
    <h2>性别：{{ person.gender}}</h2>

    <button @click="changeName">修改姓名</button>
    <button @click="changeAge">修改年龄</button>
    <button @click="changeGender">修改性别</button>
</div>
<script type="module">
    import {createApp, ref, watch, reactive} from "../../../../../js/vue.esm-browser.js";

    const app = createApp({
        setup() {
            let count = ref(0)

            watch(
                count,
                function () {
                    console.log("count 的值发生了变化");
                },
                {
                    // deep:false,
                    deep: true,
                }
            )

            let person = reactive({
                name: "abcque",
                age: 18,
                gender: "M",
            })


            function buttonClicked() {
                count.value += 1
            }

            function changeName() {
                person.name += "❤"
            }

            function changeAge() {
                person.age += 1
            }

            function changeGender() {
                if (person.gender === "M") {
                    person.gender = "W"
                } else {
                    person.gender = "M"
                }
            }

            /*watch(
                // raw style 写法默认会监听，与 deep 无关。
                person,
                function () {
                    console.log("person 的值发生了变化");
                },
                {
                    deep:false,
                    // deep: true,
                }
            )*/

            watch(
                // anonymous function style 写法默认会监听，与 deep 无关。
                () => person,
                function () {
                    console.log("person 的值发生了变化");
                },
                {
                    // deep:false,
                    deep: true,
                }
            )

            return {
                count,
                buttonClicked,
                person,
                changeName,
                changeAge,
                changeGender,
            }
        }
    })

    app.mount("#app")
</script>
</body>
</html>